package com.tz.online.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class BeanFactory {
	
	private static Properties pro = new Properties();

	static {
		// 加载配置文件中内容
		try {
			InputStream is = BeanFactory.class.
					getClassLoader().getResourceAsStream("bean.properties");
			pro.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据名称返回bean对象
	 * @param name
	 * @return
	 */
	public static Object getBean(String name) {
		Object obj = null;
		String value = pro.getProperty(name);
		try {
			Class<?> c = Class.forName(value);
			obj = c.newInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return obj;
	}

}
